<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('历史业绩') }}</span>
    </div>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="bfHistoryAchievementList" border>
      <el-table-column :label="$t('基金名称')" align="center" prop="fundName" />
      <el-table-column :label="$t('项目名称')" align="center" prop="entryName" />
      <el-table-column :label="$t('负责人')" align="center" prop="chargePerson" show-overflow-tooltip width="90" />
      <el-table-column :label="$t('投资时间')" align="center" prop="investmentTime" show-overflow-tooltip width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.investmentTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('投资金额') + $t('金额单位')" align="center" prop="investmentAmount" show-overflow-tooltip width="100">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.investmentAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('回款金额') + $t('金额单位')" align="center" prop="receivedAmount" show-overflow-tooltip width="100">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.receivedAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('回报倍数')" align="center" prop="returnMultiple" show-overflow-tooltip width="100">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.returnMultiple) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('irr')" align="center" prop="irr" show-overflow-tooltip width="80" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['bf:achievement:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['bf:achievement:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参股基金_历史业绩对话框 -->
    <el-dialog :title="$t('历史业绩')" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <bfHistoryAchievementForm ref="bfHistoryAchievementForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listBfHistoryAchievement, delBfHistoryAchievement } from '@/api/bf/achievement/bfHistoryAchievement'
import bfHistoryAchievementForm from '@/views/bf/achievement/bfHistoryAchievementForm.vue'
export default {
    components: {
        bfHistoryAchievementForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 参股基金_历史业绩表格数据
          bfHistoryAchievementList: [],
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              dealId: this.$route.query.id,
              pageNum: 1,
              pageSize: 5
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          }
      }
  },
  created() {
      this.getList()
  },
  methods: {
    /** 查询参股基金_历史业绩列表 */
    getList() {
        this.loading = true
        listBfHistoryAchievement(this.queryParams).then(response => {
            this.bfHistoryAchievementList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: this.$route.query.id,
            fundName: undefined,
            entryName: undefined,
            chargePerson: undefined,
            investmentTime: undefined,
            investmentAmount: undefined,
            receivedAmount: undefined,
            returnMultiple: undefined,
            irr: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.bfHistoryAchievementForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.bfHistoryAchievementForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delBfHistoryAchievement(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    }
  }
}
</script>
